home *** CD-ROM | disk | FTP | other *** search
- /* random.c from page 237*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h> /* randomize() uses time()*/
- main()
- { int seq[20], count = 0, i, randnum;
-
- /* initialize the random number generator*/
-
- randomize();
- while(count < 20)
- {
- randnum = random(20) + 1;
- /*is the number already present in seq[] */
- for(i = 0; i < count; i++)
- {
- if (randnum == seq[i]) break;
- }
- if( i >= count) /* Not in seq[] */
- {
- seq[count] = randnum;
- count++;
- }
- }
- /* Print the random sequence */
- printf("Random sequence (1-20) = \n");
- for(i = 0; i < count; i++)
- printf ("%d", seq[i]);
- printf("\n");
- }
-
-